package com.js.domian.model.bot;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseApi {

    public abstract String getAction();

    public abstract Object getParams();

    private String echo = null;

    public String getEcho() {
        if (StrUtil.isEmpty(echo)) {
            this.echo = IdUtil.getSnowflake().nextIdStr();
        }
        return this.echo;
    }

    public String buildJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("action", this.getAction());
        map.put("params", this.getParams());
        map.put("echo", this.getEcho());
        return JSONUtil.toJsonStr(map);
    }

}
